/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DNewSim.java
 *
 * Created on 12/12/2010, 19:02:03
 */

package tm.gui;

import java.io.File;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;

import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;

/**
 *
 * @author araruna
 */
public class DNewSim extends javax.swing.JDialog {
    
	private static final long serialVersionUID = 5471832564201585287L;
	/** A return status code - returned if Cancel button has been pressed */
    public static final int RET_CANCEL = 0;
    /** A return status code - returned if OK button has been pressed */
    public static final int RET_OK = 1;

    /** Creates new form DNewSim */
    public DNewSim(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
    public int getReturnStatus() {
        return returnStatus;
    }
    
    public File getSelectedFile() {
    	return selectedFile;
    }
    
    public long getRefreshTime() {
    	return ((SpinnerNumberModel)jSpinnerRefreshInterval.getModel()).getNumber().longValue();
    }
    
    public long getMinGreenTime() {
    	return ((SpinnerNumberModel)jSpinnerMinGreenTime.getModel()).getNumber().longValue();
    }
    
    public long getMaxRedTime() {
    	return ((SpinnerNumberModel)jSpinnerMaxRedTime.getModel()).getNumber().longValue();
    }
    
    public int getFlowRate() {
    	return Integer.parseInt(jTextFieldTraffFlowRate.getText());
    }
    
    public int getInitialFlow() {
    	return Integer.parseInt(jTextFieldInitFlowVal.getText());
    }
    
    public int getFlowModifier() {
    	return Integer.parseInt(jTextFieldFlowValModif.getText());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    	
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabelTitle = new javax.swing.JLabel();
        jPanelGraph = new javax.swing.JPanel();
        jLabelGraphFile = new javax.swing.JLabel();
        jTextFieldGraphFile = new javax.swing.JTextField();
        jButtonSelectFile = new javax.swing.JButton();
        jLabelNote = new javax.swing.JLabel();
        jPanelOptions = new javax.swing.JPanel();
        jLabelRefreshInterval = new javax.swing.JLabel();
        jLabelTraffFlowRate = new javax.swing.JLabel();
        jLabelInitFlowVal = new javax.swing.JLabel();
        jLabelFlowValModif = new javax.swing.JLabel();
        jLabelMaxRedTime = new javax.swing.JLabel();
        jLabelMinGreenTime = new javax.swing.JLabel();
        jSpinnerRefreshInterval = new javax.swing.JSpinner();
        jTextFieldTraffFlowRate = new javax.swing.JTextField();
        jTextFieldInitFlowVal = new javax.swing.JTextField();
        jTextFieldFlowValModif = new javax.swing.JTextField();
        jSpinnerMaxRedTime = new javax.swing.JSpinner();
        jSpinnerMinGreenTime = new javax.swing.JSpinner();
        jLabelRmilisec = new javax.swing.JLabel();
        jLabelFRupr = new javax.swing.JLabel();
        jLabelUnits = new javax.swing.JLabel();
        jLabelFMupr = new javax.swing.JLabel();
        jLabelGsec = new javax.swing.JLabel();
        jLabelRSec = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(tm.WMain.class).getContext().getResourceMap(DNewSim.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        jLabelTitle.setText(resourceMap.getString("jLabelTitle.text")); // NOI18N
        jLabelTitle.setName("jLabelTitle"); // NOI18N

        jPanelGraph.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanelGraph.border.title"))); // NOI18N
        jPanelGraph.setName("jPanelGraph"); // NOI18N

        jLabelGraphFile.setText(resourceMap.getString("jLabelGraphFile.text")); // NOI18N
        jLabelGraphFile.setName("jLabelGraphFile"); // NOI18N

        jTextFieldGraphFile.setEditable(false);
        jTextFieldGraphFile.setText(resourceMap.getString("jTextFieldGraphFile.text")); // NOI18N
        jTextFieldGraphFile.setName("jTextFieldGraphFile"); // NOI18N
        jTextFieldGraphFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextFieldGraphFileMouseClicked(evt);
            }
        });

        jButtonSelectFile.setText(resourceMap.getString("jButtonSelectFile.text")); // NOI18N
        jButtonSelectFile.setName("jButtonSelectFile"); // NOI18N
        jButtonSelectFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectFileActionPerformed(evt);
            }
        });

        jLabelNote.setText(resourceMap.getString("jLabelNote.text")); // NOI18N
        jLabelNote.setName("jLabelNote"); // NOI18N

        javax.swing.GroupLayout jPanelGraphLayout = new javax.swing.GroupLayout(jPanelGraph);
        jPanelGraph.setLayout(jPanelGraphLayout);
        jPanelGraphLayout.setHorizontalGroup(
            jPanelGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGraphLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNote, javax.swing.GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE)
                    .addGroup(jPanelGraphLayout.createSequentialGroup()
                        .addComponent(jLabelGraphFile)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldGraphFile, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonSelectFile)))
                .addContainerGap())
        );
        jPanelGraphLayout.setVerticalGroup(
            jPanelGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGraphLayout.createSequentialGroup()
                .addGroup(jPanelGraphLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelGraphFile)
                    .addComponent(jTextFieldGraphFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSelectFile))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabelNote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanelOptions.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanelOptions.border.title"))); // NOI18N
        jPanelOptions.setName("jPanelOptions"); // NOI18N

        jLabelRefreshInterval.setText(resourceMap.getString("jLabelRefreshInterval.text")); // NOI18N
        jLabelRefreshInterval.setName("jLabelRefreshInterval"); // NOI18N

        jLabelTraffFlowRate.setText(resourceMap.getString("jLabelTraffFlowRate.text")); // NOI18N
        jLabelTraffFlowRate.setName("jLabelTraffFlowRate"); // NOI18N

        jLabelInitFlowVal.setText(resourceMap.getString("jLabelInitFlowVal.text")); // NOI18N
        jLabelInitFlowVal.setName("jLabelInitFlowVal"); // NOI18N

        jLabelFlowValModif.setText(resourceMap.getString("jLabelFlowValModif.text")); // NOI18N
        jLabelFlowValModif.setName("jLabelFlowValModif"); // NOI18N

        jLabelMaxRedTime.setText(resourceMap.getString("jLabelMaxRedTime.text")); // NOI18N
        jLabelMaxRedTime.setName("jLabelMaxRedTime"); // NOI18N

        jLabelMinGreenTime.setText(resourceMap.getString("jLabelMinGreenTime.text")); // NOI18N
        jLabelMinGreenTime.setName("jLabelMinGreenTime"); // NOI18N

        jSpinnerRefreshInterval.setModel(new javax.swing.SpinnerNumberModel(1000, 200, 5000, 5));
        jSpinnerRefreshInterval.setToolTipText(resourceMap.getString("jSpinnerRefreshInterval.toolTipText")); // NOI18N
        jSpinnerRefreshInterval.setName("jSpinnerRefreshInterval"); // NOI18N

        jTextFieldTraffFlowRate.setText("5"); // NOI18N
        jTextFieldTraffFlowRate.setToolTipText(resourceMap.getString("jTextFieldTraffFlowRate.toolTipText")); // NOI18N
        jTextFieldTraffFlowRate.setInputVerifier(IntVerifier.getInstance());
        jTextFieldTraffFlowRate.setName("jTextFieldTraffFlowRate"); // NOI18N

        jTextFieldInitFlowVal.setText("50"); // NOI18N
        jTextFieldInitFlowVal.setToolTipText(resourceMap.getString("jTextFieldInitFlowVal.toolTipText")); // NOI18N
        jTextFieldInitFlowVal.setInputVerifier(IntVerifier.getInstance());
        jTextFieldInitFlowVal.setName("jTextFieldInitFlowVal"); // NOI18N

        jTextFieldFlowValModif.setText("0"); // NOI18N
        jTextFieldFlowValModif.setToolTipText(resourceMap.getString("jTextFieldFlowValModif.toolTipText")); // NOI18N
        jTextFieldFlowValModif.setInputVerifier(IntVerifier.getInstance());
        jTextFieldFlowValModif.setName("jTextFieldFlowValModif"); // NOI18N

        jSpinnerMaxRedTime.setModel(new javax.swing.SpinnerNumberModel(30, 10, 1200, 5));
        jSpinnerMaxRedTime.setToolTipText(resourceMap.getString("jSpinnerMaxRedTime.toolTipText")); // NOI18N
        jSpinnerMaxRedTime.setName("jSpinnerMaxRedTime"); // NOI18N

        jSpinnerMinGreenTime.setModel(new javax.swing.SpinnerNumberModel(10, 5, 600, 5));
        jSpinnerMinGreenTime.setToolTipText(resourceMap.getString("jSpinnerMinGreenTime.toolTipText")); // NOI18N
        jSpinnerMinGreenTime.setName("jSpinnerMinGreenTime"); // NOI18N

        jLabelRmilisec.setText(resourceMap.getString("jLabelRmilisec.text")); // NOI18N
        jLabelRmilisec.setToolTipText(resourceMap.getString("jLabelRmilisec.toolTipText")); // NOI18N
        jLabelRmilisec.setName("jLabelRmilisec"); // NOI18N

        jLabelFRupr.setText(resourceMap.getString("jLabelFRupr.text")); // NOI18N
        jLabelFRupr.setToolTipText(resourceMap.getString("jLabelFRupr.toolTipText")); // NOI18N
        jLabelFRupr.setName("jLabelFRupr"); // NOI18N

        jLabelUnits.setText(resourceMap.getString("jLabelUnits.text")); // NOI18N
        jLabelUnits.setToolTipText(resourceMap.getString("jLabelUnits.toolTipText")); // NOI18N
        jLabelUnits.setName("jLabelUnits"); // NOI18N

        jLabelFMupr.setText(resourceMap.getString("jLabelFMupr.text")); // NOI18N
        jLabelFMupr.setToolTipText(resourceMap.getString("jLabelFMupr.toolTipText")); // NOI18N
        jLabelFMupr.setName("jLabelFMupr"); // NOI18N

        jLabelGsec.setText(resourceMap.getString("jLabelGsec.text")); // NOI18N
        jLabelGsec.setToolTipText(resourceMap.getString("jLabelGsec.toolTipText")); // NOI18N
        jLabelGsec.setName("jLabelGsec"); // NOI18N

        jLabelRSec.setText(resourceMap.getString("jLabelRSec.text")); // NOI18N
        jLabelRSec.setToolTipText(resourceMap.getString("jLabelRSec.toolTipText")); // NOI18N
        jLabelRSec.setName("jLabelRSec"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanelOptionsLayout = new javax.swing.GroupLayout(jPanelOptions);
        jPanelOptions.setLayout(jPanelOptionsLayout);
        jPanelOptionsLayout.setHorizontalGroup(
            jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptionsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelRefreshInterval)
                    .addComponent(jLabelTraffFlowRate)
                    .addComponent(jLabelInitFlowVal)
                    .addComponent(jLabelFlowValModif)
                    .addComponent(jLabelMaxRedTime)
                    .addComponent(jLabelMinGreenTime))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jSpinnerRefreshInterval, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addComponent(jTextFieldTraffFlowRate)
                    .addComponent(jTextFieldInitFlowVal)
                    .addComponent(jTextFieldFlowValModif)
                    .addComponent(jSpinnerMaxRedTime)
                    .addComponent(jSpinnerMinGreenTime))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelRmilisec)
                    .addComponent(jLabelFRupr)
                    .addComponent(jLabelUnits)
                    .addComponent(jLabelFMupr)
                    .addComponent(jLabelGsec)
                    .addComponent(jLabelRSec))
                .addContainerGap())
        );
        jPanelOptionsLayout.setVerticalGroup(
            jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOptionsLayout.createSequentialGroup()
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelRefreshInterval)
                    .addComponent(jLabelRmilisec)
                    .addComponent(jSpinnerRefreshInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTraffFlowRate)
                    .addComponent(jLabelFRupr)
                    .addComponent(jTextFieldTraffFlowRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelInitFlowVal)
                    .addComponent(jLabelUnits)
                    .addComponent(jTextFieldInitFlowVal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelFlowValModif)
                    .addComponent(jLabelFMupr)
                    .addComponent(jTextFieldFlowValModif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMaxRedTime)
                    .addComponent(jLabelGsec)
                    .addComponent(jSpinnerMaxRedTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMinGreenTime)
                    .addComponent(jLabelRSec)
                    .addComponent(jSpinnerMinGreenTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanelOptions, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelGraph, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelTitle, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabelTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelGraph, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        doClose(RET_CANCEL);
    }//GEN-LAST:event_closeDialog

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        doClose(RET_OK);
}//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        doClose(RET_CANCEL);
}//GEN-LAST:event_cancelButtonActionPerformed

    private void jButtonSelectFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectFileActionPerformed
        showFilechooser();
    }//GEN-LAST:event_jButtonSelectFileActionPerformed

    private void jTextFieldGraphFileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextFieldGraphFileMouseClicked
        showFilechooser();
    }//GEN-LAST:event_jTextFieldGraphFileMouseClicked

    private void doClose(int retStatus) {
        if(retStatus == RET_OK && selectedFile == null)
            JOptionPane.showMessageDialog(this, resourceMap.getString("DNewSim.nofileMSG"), resourceMap.getString("DNewSim.nofileTitle"), JOptionPane.ERROR_MESSAGE);
        else {
            returnStatus = retStatus;
            setVisible(false);
            dispose();
        }
    }

    private void showFilechooser() {
    	filechooser.setSelectedFile(selectedFile);
    	
        if(filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            selectedFile = filechooser.getSelectedFile();
            jTextFieldGraphFile.setText(selectedFile.getAbsolutePath());
            jTextFieldGraphFile.setCaretPosition(jTextFieldGraphFile.getText().length());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton jButtonSelectFile;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelFMupr;
    private javax.swing.JLabel jLabelFRupr;
    private javax.swing.JLabel jLabelFlowValModif;
    private javax.swing.JLabel jLabelGraphFile;
    private javax.swing.JLabel jLabelGsec;
    private javax.swing.JLabel jLabelInitFlowVal;
    private javax.swing.JLabel jLabelMaxRedTime;
    private javax.swing.JLabel jLabelMinGreenTime;
    private javax.swing.JLabel jLabelNote;
    private javax.swing.JLabel jLabelRSec;
    private javax.swing.JLabel jLabelRefreshInterval;
    private javax.swing.JLabel jLabelRmilisec;
    private javax.swing.JLabel jLabelTitle;
    private javax.swing.JLabel jLabelTraffFlowRate;
    private javax.swing.JLabel jLabelUnits;
    private javax.swing.JPanel jPanelGraph;
    private javax.swing.JPanel jPanelOptions;
    private javax.swing.JSpinner jSpinnerMaxRedTime;
    private javax.swing.JSpinner jSpinnerMinGreenTime;
    private javax.swing.JSpinner jSpinnerRefreshInterval;
    private javax.swing.JTextField jTextFieldFlowValModif;
    private javax.swing.JTextField jTextFieldGraphFile;
    private javax.swing.JTextField jTextFieldInitFlowVal;
    private javax.swing.JTextField jTextFieldTraffFlowRate;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables

    private int returnStatus = RET_CANCEL;
    private File selectedFile = null;
    private JFileChooser filechooser = new JFileChooser(new File(System.getProperty("user.dir")));
    private static final ResourceMap resourceMap = Application.getInstance(tm.WMain.class).getContext().getResourceMap(DNewSim.class);

    private static class IntVerifier extends InputVerifier {
        private static IntVerifier instance = null;

        public static IntVerifier getInstance() {
            if(instance == null)
                instance = new IntVerifier();

            return instance;
        }

        @Override
        public boolean verify(JComponent input) {
            if(!(input instanceof javax.swing.JTextField))
                return true;
            else if(!((javax.swing.JTextField)input).getText().matches("\\d+")){
                JOptionPane.showMessageDialog(input, resourceMap.getString("DNewSim.IntVerifier.notintMSG"), resourceMap.getString("DNewSim.IntVerifier.notintTitle"), JOptionPane.ERROR_MESSAGE);
                return false;
            } else
                return true;
        }
        
    }
}
